package com.ruoyi.web.controller.lwpq;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqGsht;
import com.ruoyi.lwpq.service.ILwpqGshtService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用工单位合同Controller
 * 
 * @author ruoyi
 * @date 2022-03-09
 */
@Controller
@RequestMapping("/lwpq/gsht")
public class LwpqGshtController extends BaseController
{
    private String prefix = "lwpq/gsht";

    @Autowired
    private ILwpqGshtService lwpqGshtService;

    @RequiresPermissions("lwpq:gsht:view")
    @GetMapping()
    public String gsht()
    {
        return prefix + "/gsht";
    }

    /**
     * 查询用工单位合同列表
     */
    @RequiresPermissions("lwpq:gsht:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqGsht lwpqGsht)
    {
        startPage();
        lwpqGsht.setCreateBy(getLoginName());
        List<LwpqGsht> list = lwpqGshtService.selectLwpqGshtList(lwpqGsht);
        return getDataTable(list);
    }

    /**
     * 导出用工单位合同列表
     */
    @RequiresPermissions("lwpq:gsht:export")
    @Log(title = "用工单位合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqGsht lwpqGsht)
    {
        List<LwpqGsht> list = lwpqGshtService.selectLwpqGshtList(lwpqGsht);
        ExcelUtil<LwpqGsht> util = new ExcelUtil<LwpqGsht>(LwpqGsht.class);
        return util.exportExcel(list, "用工单位合同数据");
    }

    /**
     * 新增用工单位合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用工单位合同
     */
    @RequiresPermissions("lwpq:gsht:add")
    @Log(title = "用工单位合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqGsht lwpqGsht)
    {
        lwpqGsht.setCreateBy(getLoginName());
        return toAjax(lwpqGshtService.insertLwpqGsht(lwpqGsht));
    }

    /**
     * 修改用工单位合同
     */
    @RequiresPermissions("lwpq:gsht:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqGsht lwpqGsht = lwpqGshtService.selectLwpqGshtById(id);
        mmap.put("lwpqGsht", lwpqGsht);
        return prefix + "/edit";
    }

    /**
     * 修改保存用工单位合同
     */
    @RequiresPermissions("lwpq:gsht:edit")
    @Log(title = "用工单位合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqGsht lwpqGsht)
    {
        lwpqGsht.setUpdateBy(getLoginName());
        return toAjax(lwpqGshtService.updateLwpqGsht(lwpqGsht));
    }

    /**
     * 删除用工单位合同
     */
    @RequiresPermissions("lwpq:gsht:remove")
    @Log(title = "用工单位合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqGshtService.deleteLwpqGshtByIds(ids));
    }
}
